package com.ruoyi.web.controller.stock;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockMarket;
import com.ruoyi.stock.domain.StockTopBoard;
import com.ruoyi.stock.service.IStockMarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 股票行情Controller
 *
 * @author ruoyi
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/stock/market")
public class StockMarketController extends BaseController {
    @Autowired
    private IStockMarketService stockMarketService;

    /**
     * 查询股票行情列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockMarket stockMarket) {
        startPage();
        List<StockMarket> list = stockMarketService.selectStockMarketList(stockMarket);
        return getDataTable(list);
    }

    /**
     * 导出股票行情列表
     */
    @Log(title = "股票行情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockMarket stockMarket) {
        List<StockMarket> list = stockMarketService.selectStockMarketList(stockMarket);
        ExcelUtil<StockMarket> util = new ExcelUtil<StockMarket>(StockMarket.class);
        util.exportExcel(response, list, "股票行情数据");
    }


    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport, Date stDate) throws Exception {
        ExcelUtil<StockMarket> util = new ExcelUtil<StockMarket>(StockMarket.class);
        List<StockMarket> list = util.importExcel(file.getInputStream());
        return stockMarketService.importData(list, updateSupport, stDate);
    }

    /**
     * 获取股票行情详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockMarketService.selectStockMarketById(id));
    }

    /**
     * 新增股票行情
     */
    @Log(title = "股票行情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockMarket stockMarket)
    {
        return toAjax(stockMarketService.insertStockMarket(stockMarket));
    }

    /**
     * 修改股票行情
     */
    @Log(title = "股票行情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockMarket stockMarket)
    {
        return toAjax(stockMarketService.updateStockMarket(stockMarket));
    }

    /**
     * 删除股票行情
     */
    @Log(title = "股票行情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockMarketService.deleteStockMarketByIds(ids));
    }
}
